import React, { Component } from 'react';
import MyContext from '@/store/MyContext';

class Provider extends Component {
  state = {
    msg: 'Hi',
    todoList: []
  }
  setMsg = (msg) => {
    this.setState({
      msg
    })
  }
  addTodo = (todo) => {
    this.setState({
      todoList: [...this.state.todoList, todo]
    })
  }
  render() {
    const value = {
      msg: this.state.msg,
      todoList: this.state.todoList,
      setMsg: this.setMsg,
      addTodo: this.addTodo
    }
    return (
      <MyContext.Provider value={value}>
        {this.props.children}
      </MyContext.Provider>
    );
  }
}

export default Provider;
